package keeto.com.vn.bms.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class BMSDBHelper extends SQLiteOpenHelper {
	private String Tag ="BMSDataBase";
	 private static final int DATABASE_VERSION = 1;
	 private static final String DATABASE_NAME = "BMSDataBase";
	 private static BMSDBHelper mHelper;
	 
	 public static BMSDBHelper getInstance(Context context){
		 
		 if (mHelper == null){
			 mHelper = new BMSDBHelper(context);
		 }
		return mHelper;
		 
	 }
	 
	 
	 public BMSDBHelper(Context context){
		 super(context, DATABASE_NAME , null, DATABASE_VERSION);
	 }
	 
	public BMSDBHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		for(String sqlite : BMSDBString.CREATE_TABLE){
			db.execSQL(sqlite);
			Log.e(Tag,"Table " + sqlite);

		}
		Log.e(Tag,"Version" + db.getVersion());
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		for(String table:BMSDBString.TABLENAME){
			db.execSQL("DROP TABLE IF EXISTS" + table);
		}
		onCreate(db);
	}

}
